📝Scrapbox REST APIのwrapperを実装する
from scrapbox-userscript-std
Scrapbox REST APIのwrapperを実装する
設計
Open APIやHow method signatures are determined | Advanced Google services  |  Apps Script  |  Google Developersを参考に作る
あまり参考にならなそうなので止めた
結局一つのAPIごとに固有の関数名を振るしかなさそう
APIと関数名との対応及び実装状況
pathごとに機能が分割されているとは言い難い
pages/
/icons/done.iconapi/pages/:projectname/:pagetitle
getPage
api/pages/:projectname/:pageid/accessed
POSTのみ
updatePageAccessed
api/pages/:projectname/:pagetitle/text
getPageText
api/pages/:projectname/:pagetitle/icon
getPageIconURL
URLを組み立てるだけにする
/icons/done.iconapi/pages/:projectname/search/titles
getLinks
https://github.com/takker99/scrapbox-userscript-std/pull/30
https://github.com/takker99/scrapbox-userscript-std/pull/187
/icons/done.iconapi/pages/:projectname/search/query
searchForPages
https://github.com/takker99/scrapbox-userscript-std/pull/35
/icons/done.iconapi/pages/:projectname
listPages
https://github.com/takker99/scrapbox-userscript-std/pull/12
任意ページ分だけ取得するやつとasync generator版も提供したい
/icons/done.iconapi/pages/:projectname/replace/links
replaceLinks
https://github.com/takker99/scrapbox-userscript-std/pull/13
✅code/
api/code/:projectname/:pagetitle/:filename
getCodeBlock
https://github.com/takker99/scrapbox-userscript-std/pull/128
✅table/
api/table/:projectname/:pagetitle/:filename.csv
getTable
https://github.com/takker99/scrapbox-userscript-std/pull/109
commits/
api/commits/:projectname/:pageid
getCommits
deleted-pages/
api/deleted-pages/:projectname/:pageid
GET:
getDeletedPage
DELETE:
clearDeletedPage
✅page-snapshots/
api/page-snapshots/:projectname/:pageid
getSnapshots
https://github.com/takker99/scrapbox-userscript-std/pull/66
projects/
api/projects
/icons/done.iconGET:
listProjects()
https://github.com/takker99/scrapbox-userscript-std/pull/49
POST: projectの新規作成
createProject()
/icons/done.iconapi/projects/search/query
searchJoinedProjects
https://github.com/takker99/scrapbox-userscript-std/pull/35
/icons/done.iconapi/projects/search/watch-list
searchWatchList
https://github.com/takker99/scrapbox-userscript-std/pull/35
api/projects/:projectname
/icons/done.iconGET: project情報の取得
getProject
https://github.com/takker99/scrapbox-userscript-std/pull/6
POST: テーマの変更など
setTheme
setProjectName
api/projects/:projectname/notifications
GET: 登録されているSlack webhook URLsを取得
getSlackNotifications
POST: Slack webhook URLの追加
registerSlackNotification
api/projects/:projectname/invitations
GET: 招待リンクの取得
getInvitationLink
POST: 招待リンクのreset
resetInvitationLink
project-backup/
api/project-backup/:projectname/list
getBackupIds
api/project-backup/:projectname/:backupId.json
getBackup
page-data/
api/page-data/export/:projectname.json
exportPages
api/page-data/import/:projectname.json
importPages
api/page-data/import-finish/:projectname.json
ensureGeneratingPageMetadata
stream/
api/stream/:projectname/
getStream
listDeletedPages
feed/
api/feed/:projectname
getRSS
users/
api/users/me
/icons/done.iconGET: ユーザー情報取得
getProfile
:sparkles: Get user profile by takker99 · Pull Request #5 · takker99/scrapbox-userscript-std
POST: ユーザー情報変更
setProfile
gcs/
api/gcs/:projectname/usage
getStorageUsage
📝scrapoxのfile upload機能をscrapbox-userscript-stdに実装する
settings/
api/settings
getEnvironmentalVariables
google-map/
api/google-map/static-map
URLを組み立てるだけでいいや
getGoogleMapImageURL
api/google-map/js-map
Google Map操作用JSを取得する
これは流石にいらないだろ
/icons/done.iconembed-text/
api/embed-text/url
getWebPageTitle
api/embed-text/twitter
getTweetInfo
https://github.com/takker99/scrapbox-userscript-std/pull/31
login/
/icons/done.iconapi/login/gyazo/oauth-upload/token
getGyazoToken()
https://github.com/takker99/scrapbox-userscript-std/pull/40
api/login/gyazo/oauth-upload/revoke
api/login/gyazo/oauth-upload/token/list
login/gyazo/oauth-upload
deepl/
api/deepl/translate?text=:text
Translation mode
いっぱいあるな……takker.icon
まあ一個ずつ実装してくか。
先に共通設計を考えたほうがいい気もする……
scrapbox-userscript-stdの例外戦略
✅fetch()を外部から注入する (scrapbox-userscript-std)
命名
axiosやhonoに倣って、object chainにするか?
Tree Shakingが効くよう、submodulesをたくさん生やす
helper関数
使いやすいようにしたもの
/icons/done.iconreadLinks
api/pages/:projectname/search/titlesをasync generatorにしたもの
pagenationを意識せずに使える
bulk: trueでresponseごとに返す
型定義が難しかったので、2つの関数に分けた
readLinksBulk()
readLinks()
https://github.com/takker99/scrapbox-userscript-std/pull/30
searchForProjects
api/projects/search/queryとapi/projects/search/watch-listの統合
async generatorで結果を返す
searchProjectsBulk()
searchProjects()
/icons/done.icongetCSRFToken
CSRF tokenをwindowかapi/users/meのいずれかから取得する
#2025-03-20 08:15:56
#2024-12-24 17:15:14
#2023-06-26 10:18:40
#2023-02-05 17:03:05
#2022-07-20 08:43:04
#2022-04-08 21:39:14
#2022-03-25 06:57:01
#2022-03-24 22:03:03
#2022-02-14 13:12:02
#2022-02-12 08:59:33
#2022-02-10 07:24:21